<?php

include('phpqrcode/qrlib.php');

class QR
{
	public $rootPath;
	public $qrdecodePath;

	function __construct($rootPath)
	{
		$this->rootPath = $rootPath.'/';
		$this->qrdecodePath = $this->rootPath.'qrdecode';
	}

	public static function png($text)
	{
		QRcode::png($text, false, 4, 8);
	}

	public static function png_encrypted($text)
	{
		self::png(Security::encrypt($text));
	}

	public function read($imgFilePath)
	{
		$cmd = "python ".$this->qrdecodePath." $imgFilePath";
		exec($cmd, $r, $e);
		if ($e != 0) return false;
		return implode("\n", $r);
	}

	public function decrypt($imgFilePath)
	{
		$text = $this->read($imgFilePath);
		if ($text == false) return false;
		return Security::decrypt($text);
	}
}